<template>
  <div>
    <el-page-header @back="goBack" content="详情页面"></el-page-header>
    <el-divider content-position="left">
      <p>个人信息</p>
    </el-divider>
    <el-form :model="dataForm" ref="dataForm" class="wds-form-top" label-width="150px">
      <el-row class="wds-frame">

        <el-row class="wds-el-row" type="flex">
          <el-col :span="24">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="头像" prop="username">
                <!-- {{ dataForm.avatar }} -->
                  <img :src="dataForm.avatar" style="width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;">
              </el-form-item>
            </div>
          </el-col>
        </el-row>

        <el-row class="wds-el-row" type="flex">
          <el-col :span="12">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="用户名" prop="username">
                {{ dataForm.username }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="真实姓名" prop="realName">
                <el-tag type="info"  size="small" style="margin-right: 5px;">
                  {{ dataForm.realName }}
                </el-tag>
                <!-- {{ dataForm.realname }} -->
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row class="wds-el-row" type="flex">
          <el-col :span="12">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="邮箱" prop="email">
                {{ dataForm.email }}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="电话" prop="mobile">
                {{ dataForm.mobile }}
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row class="wds-el-row" type="flex">
          <el-col :span="12">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="组织机构" prop="organizationsId">
                <el-tag>{{ getDepatName(dataForm.organizationsId) }}</el-tag>
                <!--                {{ dataForm.organizationsId }}-->
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="角色" prop="roleIdList">
                <!--                <span v-if="Array.isArray(dataForm.roleIdList)">-->
                <!--                  {{ dataForm.roleIdList.join(', ') }}-->
                <!--                </span>-->
                <!--                <span v-else>-->
                <!--                  {{ dataForm.roleIdList }}-->
                <!--                </span>-->

                <el-tag type="warning" v-for="role in roleList" :key="role.roleId"
                        v-if="dataForm.roleIdList.includes(role.roleId)"
                        size="small" style="margin-right: 5px;">
                  {{ role.roleName }}
                </el-tag>
              </el-form-item>
            </div>
          </el-col>


        </el-row>
        <el-row class="wds-el-row" type="flex">
          <el-col :span="12">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="状态" prop="status">
                <el-tag v-if="dataForm.status===0" type="danger">禁用</el-tag>
                <el-tag v-else type="success">正常</el-tag>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="创建时间" prop="createTime">
                {{ dataForm.createTime }}
              </el-form-item>
            </div>
          </el-col>
        </el-row>

        <el-row class="wds-el-row" type="flex">
          <el-col :span="12">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="身份证号" prop="identities">
              {{dataForm.identities}}
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="wds-frame-l">
              <div class="wds-bj"></div>
              <el-form-item class="wds-frame-form-item" label="合同文件" prop="files">
                <div v-if="dataForm.files && dataForm.files.length > 0">
                  <i
                    v-for="(fileUrl, index) in dataForm.files"
                    :key="index"
                    class="el-icon-document"
                    style="cursor: pointer; margin-right: 20px; color: red;"
                    @click="openPdf(fileUrl)"
                  ></i>
                </div>
                <span v-else>无合同文件</span>
              </el-form-item>
            </div>
          </el-col>
        </el-row>

      </el-row>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dataForm: {
        username: '',
        realname: '',
        avatar: '',
        mobile: '',
        email: '',
        roleIdList: [],
        organizationsId: '',
        status: '',
        createTime: '',
        files:[],
        identity:''
      },
      departList: [],
      roleList: [],
    };
  },
  activated() {
    // this.getRoleList();
  },

  created() {
    this.getDepartList();
    this.getRoleList();
  },
  methods: {
    // 打开 PDF 文件
    openPdf(ossFileUrl) {
      window.open(ossFileUrl);
    },
    goBack() {
      this.$emit('goBack');
    },
    init(row) {
     // if(this.dataForm.files)
      this.dataForm = row;
      console.log("row"+JSON.stringify( this.dataForm))
    },
    // 获取角色列表
    getRoleList() {
      this.$http({
        url: this.$http.adornUrl("/sys/role/select"),
        method: "get",
        params: this.$http.adornParams()
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.roleList = data.list;
          console.log("角色列表", this.roleList);
        } else {
          console.error("获取角色列表失败", data.msg);
        }
      }).catch(error => {
        console.error("获取角色列表失败", error);
      });
    },
    // 获取部门列表
    getDepartList() {
      this.$http({
        url: this.$http.adornUrl('/sys/organizations/list'),
        method: 'get',
        data: this.$http.adornData({})
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.departList = data.page.list.map(item => ({
            value: item.id,
            label: item.name
          }));
          console.log("部门列表", this.departList);
        } else {
          console.error("获取部门列表失败", data.msg);
        }
      }).catch(error => {
        console.error("获取部门列表失败", error);
      });
    },

    getDepatName(organizationsId) {
      const depart = this.departList.find(item => item.value === organizationsId);
      return depart ? depart.label : '未分配';
    },
  },
};
</script>

<style>
.wds-form-top {
  margin-top: 8px;
}

.wds-frame {
  margin-left: 15px;
  margin-right: 15px;
  border-top: 1px solid rgba(184, 194, 215, 0.4);
  border-right: 1px solid rgba(184, 194, 215, 0.4);
}

.wds-frame-l {
  position: relative;
  width: 100%;
  height: 100%;
  border-left: 1px solid rgba(184, 194, 215, 0.4);
  border-bottom: 1px solid rgba(184, 194, 215, 0.4);
}

.wds-frame-form-item .el-form-item__label {
  padding-top: 6px;
  padding-left: 4px;
  line-height: 20px !important;
  width: 130px !important;
  color: #054999;
}

.wds-bj {
  width: 140px;
  border-right: 1px solid rgba(184, 194, 215, 0.4);
  height: 100%;
  position: absolute;
}

.wds-frame-form-item {
  max-height: 25px;
  padding-top: 6px;
  padding-left: 4px;
  line-height: 20px !important;
  color: #054999;
}

.el-divider .el-divider__text {
  font-size: 18px !important;
  font-weight: 800;
}
</style>
